package org.graduation.IM.service.socket;

import com.corundumstudio.socketio.SocketIOClient;
import lombok.extern.slf4j.Slf4j;
import org.graduation.model.common.IM.Message;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Slf4j
public abstract class SingleUserSocketService{
    /**
     * 用户和客户端的映射
     */
    private Map<Integer, SocketIOClient> userMap = new ConcurrentHashMap<>();

    public void login(Integer uid, SocketIOClient client) {
        userMap.put(uid, client);
        log.info("用户{}登录", uid);
    }

    public void logout(Integer uid) {
        userMap.remove(uid);
        log.info("用户{}退出", uid);
    }

    protected SocketIOClient getClient(Integer uid) {
        return userMap.get(uid);
    }
    /**
     * 1对1发送消息
     *
     * @param message
     */
    public abstract void sendMessage(Message message);

    /**
     * 判断是否是好友
     * @param uidA
     * @param uidB
     * @return
     */
    protected abstract boolean checkFriend(Integer uidA, Integer uidB);

}
